/*
 *************************************************************************
 * The contents of this file are subject to the Openbravo  Public  License
 * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
 * Version 1.1  with a permitted attribution clause; you may not  use this
 * file except in compliance with the License. You  may  obtain  a copy of
 * the License at http://www.openbravo.com/legal/license.html 
 * Software distributed under the License  is  distributed  on  an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific  language  governing  rights  and  limitations
 * under the License. 
 * The Original Code is Openbravo ERP. 
 * The Initial Developer of the Original Code is Openbravo SLU 
 * All portions are Copyright (C) 2001-2011 Openbravo SLU 
 * All Rights Reserved. 
 * Contributor(s):  ______________________________________.
 ************************************************************************
 */
package org.openbravo.furniture.info;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.sql.Connection;
import java.util.StringTokenizer;


import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.openbravo.base.secureApp.HttpSecureAppServlet;
import org.openbravo.base.secureApp.VariablesSecureApp;
import org.openbravo.dal.core.OBContext;
import org.openbravo.dal.service.OBDal;
import org.openbravo.erpCommon.utility.AttributeSetInstanceValue;
import org.openbravo.erpCommon.utility.SequenceIdData;
import org.openbravo.erpCommon.utility.DateTimeData;
import org.openbravo.erpCommon.utility.OBError;
import org.openbravo.erpCommon.utility.Utility;
import org.openbravo.model.common.plm.AttributeSet;
import org.openbravo.model.common.plm.AttributeUse;
import org.openbravo.model.common.plm.Product;
import org.openbravo.utils.Replace;
import org.openbravo.xmlEngine.XmlDocument;
import org.openbravo.utils.Replace;

public class Furnitureattribute extends HttpSecureAppServlet {
  private static final long serialVersionUID = 1L;

  public void init(ServletConfig config) {
    super.init(config);
    boolHist = false;
  }

  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
      ServletException {
    VariablesSecureApp vars = new VariablesSecureApp(request);

    if (vars.commandIn("DEFAULT") || vars.commandIn("KEY")) {
      //String strNameValue = vars.getRequestGlobalVariable("inpNameValue", "Furnitureattribute.instance");
      String strNameValue = vars.getRequestGlobalVariable("inpKeyValue","Furnitureattribute.instance");
      String strProduct = vars.getRequestGlobalVariable("inpProduct","Furnitureattribute.product");
      vars.getRequestGlobalVariable("inpwindowId", "Furnitureattribute.windowId");
      vars.getRequestGlobalVariable("inpLocatorId", "Furnitureattribute.locatorId");
      vars.getRequestGlobalVariable("inpTabId", "Furnitureattribute.tabId");
      log4j.debug("Furniture attribute selector - name value: "+strNameValue);
      log4j.debug("Furniture attribute selector - product: "+strProduct);
      String strAttributeSet = "";
      String strProductInstance = "";
      if (strNameValue.equals("") || strNameValue.equals("0")) {
        vars.setSessionValue("Furnitureattribute.instance", "");
        FurnitureattributeData[] data = FurnitureattributeData.selectProductAttr(this,
            strProduct);
        if (data != null && data.length > 0 && !data[0].mAttributesetId.equals("")) {
          strAttributeSet = data[0].mAttributesetId;
          strProductInstance = data[0].mAttributesetinstanceId;
        }
      } else {
        strAttributeSet = FurnitureattributeData.selectAttributeSet(this, strNameValue);
      }
      vars.setSessionValue("Furnitureattribute.attribute", strAttributeSet);
      vars.setSessionValue("Furnitureattribute.productInstance", strProductInstance);
      vars.setSessionValue("Furnitureattribute.close", "N");
      if (strAttributeSet.equals("") || strAttributeSet.equals("0"))
        advisePopUp(request, response, "INFO", Utility.messageBD(this, "Info", vars.getLanguage()),
            Utility.messageBD(this, "PAttributeNoSelection", vars.getLanguage()));
      else
        response.sendRedirect(strDireccion + request.getServletPath() + "?Command=DISPLAY");
    } else if (vars.commandIn("DISPLAY")) {
      String strNameValue = vars.getGlobalVariable("inpInstance", "Furnitureattribute.instance","");
      String strAttributeSet = vars.getGlobalVariable("inpAttribute","Furnitureattribute.attribute");
      String strProductInstance = vars.getGlobalVariable("inpProductInstance","Furnitureattribute.productInstance", "");
      String strWindowId = vars.getGlobalVariable("inpwindowId", "Furnitureattribute.windowId","");
      String strTabId = vars.getGlobalVariable("inpTabId", "Furnitureattribute.tabId", "");
      String strLocator = vars.getGlobalVariable("inpLocatorId", "Furnitureattribute.locatorId","");
      String strProduct = vars.getGlobalVariable("inpProduct", "Furnitureattribute.product", "");
      String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
      String strKey = vars.getStringParameter(strNameValue, "");
	  String strType = vars.getStringParameter("inpType", "");

      log4j.debug("Furniture attribute selector - name value: "+strNameValue);
      log4j.debug("Furniture attribute selector - name value: "+strAttributeSet);
      log4j.debug("Furniture attribute selector - name value: "+strProductInstance);
      log4j.debug("Furniture attribute selector - name value: "+strWindowId);
      log4j.debug("Furniture attribute selector - name value: "+strTabId);
      log4j.debug("Furniture attribute selector - name value: "+strLocator);
      log4j.debug("Furniture attribute selector - name value: "+strProduct);
      log4j.debug("Furniture attribute selector - name value: "+strIsSOTrx);

      log4j.debug("strType: "+strType);



      
	  if (strIsSOTrx.equals("")) strIsSOTrx = "N";
      if (log4j.isDebugEnabled()) log4j.debug("strNameValue: " + strNameValue);
      String strAttrSetValueType = "";
      OBContext.setAdminMode();
      try {
        final Product product = OBDal.getInstance().get(Product.class, strProduct);
        if (product != null) {
          strAttrSetValueType = product.getUseAttributeSetValueAs();
        }
      } finally {
        OBContext.restorePreviousMode();
      }
      if (!strAttributeSet.equals("")) {
        if ("F".equals(strAttrSetValueType))
          advisePopUp(request, response, "INFO",
              Utility.messageBD(this, "Info", vars.getLanguage()),
              Utility.messageBD(this, "AttrSetValTypeSpecification", vars.getLanguage()));
        else
          printPage(response, vars, strNameValue, strAttributeSet, strProductInstance, strWindowId,
              strTabId, strLocator, strIsSOTrx, strProduct, strKey, strType);
      } else
        advisePopUp(request, response, "INFO", Utility.messageBD(this, "Info", vars.getLanguage()),
            Utility.messageBD(this, "PAttributeNoSelection", vars.getLanguage()));
    } else if (vars.commandIn("SOFA")) {
      String strAttributeSet = vars.getRequiredStringParameter("inpAttribute");
      String strInstance = vars.getStringParameter("inpInstance");
      String strWindowId = vars.getStringParameter("inpwindowId");
      String strTabId = vars.getStringParameter("inpTabId");
      String strProduct = vars.getRequestGlobalVariable("inpProduct","Furnitureattribute.product");
      String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);


	  String strArmazonId = vars.getStringParameter("inpArmazonId", "");
	  String strAsientosId = vars.getStringParameter("inpAsientosId", "");
	  String strRespaldosId = vars.getStringParameter("inpRespaldosId", "");
	  String strApoyaBrazosId = vars.getStringParameter("inpApoyaBrazosId", "");
	  String strPuffsId = vars.getStringParameter("inpPuffsId", "");
	  String strCojinesId = vars.getStringParameter("inpCojinesId", "");

	  String strAttPrice = vars.getStringParameter("inpAttPrice","0");
	  	  
	  String mAttributesetInstanceId = FurnitureattributeData.selectInstanceSofaExists(this, strAttributeSet,
		  strArmazonId, strAsientosId, strRespaldosId, strApoyaBrazosId, strPuffsId, strCojinesId, strAttPrice);

	  if ("".equals(mAttributesetInstanceId)) {
		  String strmAttributeinstanceId = "";
		  mAttributesetInstanceId = SequenceIdData.getUUID();
		  String valueatt="";
		  
		  FurnitureattributeData.insertHeader(this, mAttributesetInstanceId, vars.getClient(), vars.getOrg(), vars.getUser(), strAttributeSet, "", "", "", "", "N", "", 
			  valueatt,"N","N","N","N","N","N","N","N","S",strAttPrice);

		  String strMixAttMain = FurnitureattributeData.selectMixAttMain(this);

		  if (!"".equals(strArmazonId)) {
				    FurnitureattributeData[] dataArmazon = FurnitureattributeData.selectAttributevalue(this, strArmazonId);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLineSofa(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strArmazonId, dataArmazon[0].name, "", "","10","N");
					valueatt = valueatt + " Armazon: "+dataArmazon[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLineSofa(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","10","N");
		  }

		  if (!"".equals(strAsientosId)) {
				    FurnitureattributeData[] dataAsientos = FurnitureattributeData.selectAttributevalue(this, strAsientosId);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLineSofa(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strAsientosId, dataAsientos[0].name, "", "","20","N");
					valueatt = valueatt + " Asientos: "+dataAsientos[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLineSofa(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","20","N");
		  }

		  if (!"".equals(strRespaldosId)) {
				    FurnitureattributeData[] dataRespaldos = FurnitureattributeData.selectAttributevalue(this, strRespaldosId);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLineSofa(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strRespaldosId, dataRespaldos[0].name, "", "","30","N");
					valueatt = valueatt + " Respaldos: "+dataRespaldos[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLineSofa(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","30","N");
		  }

		  if (!"".equals(strApoyaBrazosId)) {
				    FurnitureattributeData[] dataApoyaBrazo= FurnitureattributeData.selectAttributevalue(this, strApoyaBrazosId);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLineSofa(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strApoyaBrazosId, dataApoyaBrazo[0].name, "", "","40","N");
					valueatt = valueatt + " Apoya-Brazos: "+dataApoyaBrazo[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLineSofa(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","40","N");
		  }

		  if (!"".equals(strPuffsId)) {
				    FurnitureattributeData[] dataPuff= FurnitureattributeData.selectAttributevalue(this, strPuffsId);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLineSofa(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strPuffsId, dataPuff[0].name, "", "","50","N");
					valueatt = valueatt + " Puffs: "+dataPuff[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLineSofa(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","50","N");
		  }

		  if (!"".equals(strCojinesId)) {
				    FurnitureattributeData[] dataCojines= FurnitureattributeData.selectAttributevalue(this, strCojinesId);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLineSofa(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strCojinesId, dataCojines[0].name, "", "","60","N");
					valueatt = valueatt + " Cojines: "+dataCojines[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLineSofa(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","60","N");
		  }
		FurnitureattributeData.updateHeader(this, valueatt, mAttributesetInstanceId);
	  }

	  vars.setSessionValue("Furnitureattribute.instance", mAttributesetInstanceId);
      vars.setSessionValue("Furnitureattribute.attribute", strAttributeSet);
      vars.setSessionValue("Furnitureattribute.close", "Y");
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=DISPLAY");
	} else if (vars.commandIn("SAVE")) {
      String strAttributeSet = vars.getRequiredStringParameter("inpAttribute");
      String strInstance = vars.getStringParameter("inpInstance");
      String strWindowId = vars.getStringParameter("inpwindowId");
      String strTabId = vars.getStringParameter("inpTabId");
      String strProduct = vars.getRequestGlobalVariable("inpProduct","Furnitureattribute.product");
      String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);



      // Obtain the attribute set instance id from the window. If empty, the attribute is new, so inserts all the values.
      // If set, update all the values (or insert the new ones, if does not exist.
      String strSetInstance = vars.getStringParameter("inpmAttributesetinstanceId", "");

      // Set Attributes
      /*AttributeSetInstanceValue attSetValue = new AttributeSetInstanceValue(
          vars.getStringParameter("inplot"), vars.getStringParameter("inpserno"),
          vars.getStringParameter("inpDateFrom"), vars.getStringParameter("inpislocked", "N"),
          vars.getStringParameter("inplockDescription"));
      AttributeSet attSet = OBDal.getInstance().get(AttributeSet.class, strAttributeSet);
      HashMap<String, String> attValues = new HashMap<String, String>();
      for (AttributeUse attrUse : attSet.getAttributeUseList()) {
        final String elementName = attrUse.getAttribute().getName();
        if (attrUse.isActive() && attrUse.getAttribute().isActive()) {
          if (attrUse.getAttribute().isMandatory()) {
            attValues.put(replace(elementName),
                vars.getRequiredStringParameter("inp" + replace(elementName)));
          } else {
            attValues.put(replace(elementName),
                vars.getStringParameter("inp" + replace(elementName)));
          }
        }
      }*/
      
      // Gets the base attribute
	  String strAllDoors= vars.getStringParameter("inpAllDoors","N");
	  String strPlatDoors= vars.getStringParameter("inpPlatfonesDoors","N");
	  String strIzdaDchaDoors= vars.getStringParameter("inpIzdaDchaDoors","N");
	  String strUpdownDoors= vars.getStringParameter("inpUpDownDoors","N");

	  String strAllDrawers= vars.getStringParameter("inpAllDrawers","N");
	  String strPlatDrawers= vars.getStringParameter("inpPlatfonesDrawers","N");
	  String strIzdaDchaDrawers= vars.getStringParameter("inpIzdaDchaDrawers","N");
	  String strMiUpdownDrawers= vars.getStringParameter("inpUpDownDrawers","N");

	  String strAttPrice = vars.getStringParameter("inpAttPrice","0");




      String strBaseAttributeId = vars.getStringParameter("inpmAttributevalueId", "");
      String strBaseName = FurnitureattributeData.selectBase(this, strBaseAttributeId);
      log4j.debug("Furniture attribute selector - base attribute: "+strBaseAttributeId + " " + strBaseName);

      // Gets the metal attribute
      String strMetalAttributeId = vars.getStringParameter("inpmAttributevalueMetalId", "");
      String strMetalName = FurnitureattributeData.selectBase(this, strMetalAttributeId);
      log4j.debug("Furniture attribute selector - metal attribute: "+strMetalAttributeId + " " + strMetalName);

      // Gets the mixed attributes
      String strMixAttributeId1 = vars.getStringParameter("inpmAttributevalueMixId1", "");
	  String strMixAttributeId2 = vars.getStringParameter("inpmAttributevalueMixId2", "");
      String strMixAttributeId3 = vars.getStringParameter("inpmAttributevalueMixId3", "");
	  String strMixAttributeId4 = vars.getStringParameter("inpmAttributevalueMixId4", "");
      String strMixAttributeId5 = vars.getStringParameter("inpmAttributevalueMixId5", "");
	  String strMixAttributeId6 = vars.getStringParameter("inpmAttributevalueMixId6", "");
      String strMixAttributeId7 = vars.getStringParameter("inpmAttributevalueMixId7", "");
	  String strMixAttributeId8 = vars.getStringParameter("inpmAttributevalueMixId8", "");
      String strMixAttributeId9 = vars.getStringParameter("inpmAttributevalueMixId9", "");
	  String strMixAttributeId10 = vars.getStringParameter("inpmAttributevalueMixId10", "");
      String strMixAttributeId11 = vars.getStringParameter("inpmAttributevalueMixId11", "");
	  String strMixAttributeId12 = vars.getStringParameter("inpmAttributevalueMixId12", "");

      // Gets the drawer attributes
      String strDrawerAttributeId1 = vars.getStringParameter("inpmAttributevalueDrawerId1", "");
	  String strDrawerAttributeId2 = vars.getStringParameter("inpmAttributevalueDrawerId2", "");
      String strDrawerAttributeId3 = vars.getStringParameter("inpmAttributevalueDrawerId3", "");
	  String strDrawerAttributeId4 = vars.getStringParameter("inpmAttributevalueDrawerId4", "");
      String strDrawerAttributeId5 = vars.getStringParameter("inpmAttributevalueDrawerId5", "");
	  String strDrawerAttributeId6 = vars.getStringParameter("inpmAttributevalueDrawerId6", "");
      String strDrawerAttributeId7 = vars.getStringParameter("inpmAttributevalueDrawerId7", "");
	  String strDrawerAttributeId8 = vars.getStringParameter("inpmAttributevalueDrawerId8", "");
      String strDrawerAttributeId9 = vars.getStringParameter("inpmAttributevalueDrawerId9", "");
	  String strDrawerAttributeId10 = vars.getStringParameter("inpmAttributevalueDrawerId10", "");
      String strDrawerAttributeId11 = vars.getStringParameter("inpmAttributevalueDrawerId11", "");
	  String strDrawerAttributeId12 = vars.getStringParameter("inpmAttributevalueDrawerId12", "");

	  // Gets the handle quantity
      String strHandleQuantityId1 = vars.getStringParameter("inpQuantityHandle1", "");
      String strHandleQuantityId2 = vars.getStringParameter("inpQuantityHandle2", "");
      String strHandleQuantityId3 = vars.getStringParameter("inpQuantityHandle3", "");
      String strHandleQuantityId4 = vars.getStringParameter("inpQuantityHandle4", "");
	  // Gets the handle type
      String strHandleId1 = vars.getStringParameter("inppecHandleId1", "");
      String strHandleId2 = vars.getStringParameter("inppecHandleId2", "");
      String strHandleId3 = vars.getStringParameter("inppecHandleId3", "");
      String strHandleId4 = vars.getStringParameter("inppecHandleId4", "");
	  // Gets the handle colour
	  String strHandleColourId1 = vars.getStringParameter("inpmAttributevalueHandleId1", "");
      String strHandleColourId2 = vars.getStringParameter("inpmAttributevalueHandleId2", "");
      String strHandleColourId3 = vars.getStringParameter("inpmAttributevalueHandleId3", "");
      String strHandleColourId4 = vars.getStringParameter("inpmAttributevalueHandleId4", "");
      String strHandleName = FurnitureattributeData.selectHandleName(this, strHandleId1);
      log4j.debug("Furniture attribute selector - handle: "+strHandleId1 + " " + strHandleName);

      // We have to check if the attributes match any other attribute set instance created in the system. To do that use method attributesetinstanceCheck method

      //String attributesetinstance = attributesetinstanceCheck(vars, strBaseAttributeId, strMetalAttributeId, strMixAttributeId, strHandleId);
	  String attributesetinstance = "";
      log4j.debug("Furniture attribute - creating attribute set instance - exists other instance: "+attributesetinstance);

      // If all the parameters match, the attribute set instance exists, so, the system has to use it.
      String mAttributesetInstanceId = FurnitureattributeData.selectInstanceExists(this, strAttributeSet,
		  strAllDoors,strIzdaDchaDoors,strUpdownDoors,strPlatDoors,
		  strAllDrawers,strIzdaDchaDrawers,strMiUpdownDrawers,strPlatDrawers,strBaseAttributeId,strMetalAttributeId,
		  strMixAttributeId1,strMixAttributeId2,strMixAttributeId3,strMixAttributeId4,strMixAttributeId5,strMixAttributeId6,strMixAttributeId7,strMixAttributeId8,strMixAttributeId9,strMixAttributeId10,strMixAttributeId11,strMixAttributeId12,
		  strDrawerAttributeId1,strDrawerAttributeId2,strDrawerAttributeId3,strDrawerAttributeId4,strDrawerAttributeId5,strDrawerAttributeId6,strDrawerAttributeId7,strDrawerAttributeId8,strDrawerAttributeId9,strDrawerAttributeId10,strDrawerAttributeId11,strDrawerAttributeId12,
		  strHandleQuantityId1,strHandleQuantityId2,strHandleQuantityId3,strHandleQuantityId4,
		  strHandleId1,strHandleId2,strHandleId3,strHandleId4,
		  strHandleColourId1,strHandleColourId2,strHandleColourId3,strHandleColourId4,strAttPrice);
	
	 log4j.debug("mAttributesetInstanceId: " +mAttributesetInstanceId);
	  
	      log4j.debug("ASDFJLAKSJDFLAJSDLKJFALK: " +strAttributeSet);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +  strAllDoors);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strIzdaDchaDoors);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strUpdownDoors);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strPlatDoors);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strAllDrawers);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strIzdaDchaDrawers);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strMiUpdownDrawers);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strPlatDrawers);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strBaseAttributeId);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strMetalAttributeId);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strMixAttributeId1);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strMixAttributeId2);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strMixAttributeId3);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strMixAttributeId4);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strMixAttributeId5);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strMixAttributeId6);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strMixAttributeId7);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strMixAttributeId8);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strMixAttributeId9);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strMixAttributeId10);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strMixAttributeId11);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strMixAttributeId12);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strDrawerAttributeId1);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strDrawerAttributeId2);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strDrawerAttributeId3);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strDrawerAttributeId4);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strDrawerAttributeId5);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strDrawerAttributeId6);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strDrawerAttributeId7);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strDrawerAttributeId8);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strDrawerAttributeId9);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strDrawerAttributeId10);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strDrawerAttributeId11);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strDrawerAttributeId12);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strHandleQuantityId1);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strHandleQuantityId2);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strHandleQuantityId3);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strHandleQuantityId4);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strHandleId1);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strHandleId2);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strHandleId3);
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strHandleId4);
 		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strHandleColourId1);
  		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strHandleColourId2);
  		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strHandleColourId3);
  		  log4j.debug("Furniture attribute selector - new attribute set instance id: " +strHandleColourId4);

	  
	  if ("".equals(mAttributesetInstanceId)) {
		  // Inserts the attribute set instance
		  //
		  mAttributesetInstanceId = SequenceIdData.getUUID();
		  log4j.debug("Furniture attribute selector - new attribute set instance id: " + mAttributesetInstanceId);

		String valueatt="";
		if (!"".equals(strBaseName) && strBaseName != null )
		{
			valueatt = "Estructura: " + strBaseName+"; ";
		}
		if (!"".equals(strMetalName) && strMetalName!= null )
		{
			valueatt = valueatt + "Detalles: " + strMetalName+"; ";
		}

		if ((!"".equals(strMixAttributeId1) && strMixAttributeId1!=null) || (!"".equals(strMixAttributeId2) && strMixAttributeId2!=null) ||
			(!"".equals(strMixAttributeId3) && strMixAttributeId3!=null) || (!"".equals(strMixAttributeId4) && strMixAttributeId4!=null) ||
			(!"".equals(strMixAttributeId5) && strMixAttributeId5!=null) || (!"".equals(strMixAttributeId6) && strMixAttributeId6!=null) ||
			(!"".equals(strMixAttributeId7) && strMixAttributeId7!=null) || (!"".equals(strMixAttributeId8) && strMixAttributeId8!=null) ||
			(!"".equals(strMixAttributeId9) && strMixAttributeId9!=null) || (!"".equals(strMixAttributeId10) && strMixAttributeId10!=null) ||
			(!"".equals(strMixAttributeId11) && strMixAttributeId11!=null) || (!"".equals(strMixAttributeId12) && strMixAttributeId12!=null))
		{
			valueatt = valueatt + "Puertas: " + (strAllDoors.equals("Y") ? "Todas-" : "")+(strPlatDoors.equals("Y") ? "Platfones-" : "")+
				(strIzdaDchaDoors.equals("Y") ? "Izda-Dcha" : "")+(strUpdownDoors.equals("Y") ? "Arriba-Abajo" : "")+"; ";
		}


		if ((!"".equals(strDrawerAttributeId1) && strDrawerAttributeId1!=null) || (!"".equals(strDrawerAttributeId2) && strDrawerAttributeId2!=null) ||
			(!"".equals(strDrawerAttributeId3) && strDrawerAttributeId3!=null) || (!"".equals(strDrawerAttributeId4) && strDrawerAttributeId4!=null) ||
			(!"".equals(strDrawerAttributeId5) && strDrawerAttributeId5!=null) || (!"".equals(strDrawerAttributeId6) && strDrawerAttributeId6!=null) ||
			(!"".equals(strDrawerAttributeId7) && strDrawerAttributeId7!=null) || (!"".equals(strDrawerAttributeId8) && strDrawerAttributeId8!=null) ||
			(!"".equals(strDrawerAttributeId9) && strDrawerAttributeId9!=null) || (!"".equals(strDrawerAttributeId10) && strDrawerAttributeId10!=null) ||
			(!"".equals(strDrawerAttributeId11) && strDrawerAttributeId11!=null) || (!"".equals(strDrawerAttributeId12) && strDrawerAttributeId12!=null))
		{
			valueatt = valueatt + "Cajones: " + (strAllDrawers.equals("Y") ? "Todas-" : "")+(strPlatDrawers.equals("Y") ? "Platfones-" : "")+
				(strIzdaDchaDrawers.equals("Y") ? "Izda-Dcha" : "")+(strMiUpdownDrawers.equals("Y") ? "Arriba-Abajo" : "")+"; ";
		}
		  FurnitureattributeData.insertHeader(this, mAttributesetInstanceId, vars.getClient(), vars.getOrg(), vars.getUser(), strAttributeSet, "", "", "", "", "N", "", 
			  valueatt,strAllDoors,strPlatDoors,strIzdaDchaDoors,strUpdownDoors,strAllDrawers,strPlatDrawers,strIzdaDchaDrawers,strMiUpdownDrawers,"A",strAttPrice);
		  String strmAttributeinstanceId = "";
		  //Insert base colour
		String strBaseAttMain = FurnitureattributeData.selectBaseAttMain(this);
		  if (!"".equals(strBaseAttributeId)) {
		   FurnitureattributeData[] dataValue = FurnitureattributeData.selectAttributevalue(this, strBaseAttributeId);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insert(this, strmAttributeinstanceId, mAttributesetInstanceId, strBaseAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strBaseAttributeId, dataValue[0].name, "", "","","N");
		  } else {
		   
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insert(this, strmAttributeinstanceId, mAttributesetInstanceId, strBaseAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						"", "", "", "","","N");
		  }

		  /*if ("".equals(strSetInstance)) {
			// Insert base color
				if (!"".equals(strBaseAttributeId)) {
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insert(this, strmAttributeinstanceId, mAttributesetInstanceId, dataValue[0].mAttributeId, vars.getClient(), vars.getOrg(), vars.getUser(), strBaseAttributeId, dataValue[0].name, "", "");
				}
		  } else {
			// Update base color
				FurnitureattributeData[] dataAttributeBase = FurnitureattributeData.selectAttributeBase(this, strSetInstance);
				if (dataAttributeBase != null && dataAttributeBase.length > 0) {
					if (!"".equals(strBaseAttributeId)) {
						FurnitureattributeData.update(this, vars.getUser(), strBaseAttributeId, dataValue[0].name, strSetInstance,  dataAttributeBase[0].mAttributeId);
						FurnitureattributeData.updateHeaderDescription(this, vars.getUser(), dataValue[0].name, strSetInstance);
					} else {
						// Exists attribute but the attribute base is empty, so the entry in attributeinstance must be deleted
						FurnitureattributeData.deleteAttribute(this, strmAttributeinstanceId, strBaseAttributeId);
						FurnitureattributeData.updateHeaderDescription(this, vars.getUser(), "", strSetInstance);
					}
				} else {
					if (!"".equals(strBaseAttributeId)) {
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insert(this, strmAttributeinstanceId, mAttributesetInstanceId, dataValue[0].mAttributeId, vars.getClient(), vars.getOrg(), vars.getUser(), strBaseAttributeId, dataValue[0].name, "", "");
				  }
				}
		  }*/

		  // Insert metal attributes
			String strMetalAttMain = FurnitureattributeData.selectMetalAttMain(this);
		  if (!"".equals(strMetalAttributeId)) {
			  		  FurnitureattributeData[] dataMetalValue = FurnitureattributeData.selectAttributevalue(this, strMetalAttributeId);
						log4j.debug("Furniture data metal value - dataMetalValue.length: "+dataMetalValue.length + " metal attribute id: "+strMetalAttributeId);
					  strmAttributeinstanceId = SequenceIdData.getUUID();
					  FurnitureattributeData.insert(this, strmAttributeinstanceId, mAttributesetInstanceId, strMetalAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						  strMetalAttributeId, dataMetalValue[0].name, "", "","","N");
		  } else {
					  strmAttributeinstanceId = SequenceIdData.getUUID();
					  FurnitureattributeData.insert(this, strmAttributeinstanceId, mAttributesetInstanceId, strMetalAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						  "", "", "", "","","N");
		  }
		  /*strmAttributeinstanceId = "";
		  if ("".equals(strSetInstance)) {
				// Insert metal color
				if (!"".equals(strMetalAttributeId)) {
					  strmAttributeinstanceId = SequenceIdData.getUUID();
					  FurnitureattributeData.insert(this, strmAttributeinstanceId, mAttributesetInstanceId, dataMetalValue[0].mAttributeId, vars.getClient(), vars.getOrg(), vars.getUser(), strMetalAttributeId, dataMetalValue[0].name, "", "");
				}
		  } else {
				// Update metal color
				FurnitureattributeData[] dataAttributeMetal = FurnitureattributeData.selectAttributeMetal(this, strSetInstance);
				log4j.debug("Furniture inside the else updating or inserting - metal - dataAttributeMetal.length: "+dataAttributeMetal.length);
				if (dataAttributeMetal != null && dataAttributeMetal.length > 0) {
					log4j.debug("Furniture metal inside the if updating: "+dataAttributeMetal.length);
					if (!"".equals(strMetalAttributeId)) {
						FurnitureattributeData.update(this, vars.getUser(), strMetalAttributeId, dataMetalValue[0].name, strSetInstance,  dataAttributeMetal[0].mAttributeId);
						FurnitureattributeData.updateHeaderDescription(this, vars.getUser(), strBaseName+" - "+dataMetalValue[0].name+" - "+strHandleName, strSetInstance);
					} else {
						FurnitureattributeData.deleteAttribute(this, strmAttributeinstanceId, strMetalAttributeId);
						FurnitureattributeData.updateHeaderDescription(this, vars.getUser(), strBaseName, strSetInstance);
					}
				} else {
					log4j.debug("Furniture metal inside the insert - metal attribute: "+strMetalAttributeId);
					 if (!"".equals(strMetalAttributeId)) {
						log4j.debug("Furniture metal inserted");
						strmAttributeinstanceId = SequenceIdData.getUUID();
						FurnitureattributeData.insert(this, strmAttributeinstanceId, mAttributesetInstanceId, dataMetalValue[0].mAttributeId, vars.getClient(), vars.getOrg(), vars.getUser(), strMetalAttributeId, strBaseName+" - "+dataMetalValue[0].name, "", "");
					  }
				}
			}*/


      // Insert all the attribute sets related to this attribute set instance
	   //Insert mix colour 

		String strMixAttMain = FurnitureattributeData.selectMixAttMain(this);

		  if (!"".equals(strMixAttributeId1)) {
				    FurnitureattributeData[] dataMixColour1 = FurnitureattributeData.selectAttributevalue(this, strMixAttributeId1);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strMixAttributeId1, dataMixColour1[0].name, "", "","10","N");
					valueatt = valueatt + " Puerta1: "+dataMixColour1[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","10","N");
		  }
		  if (!"".equals(strMixAttributeId2)) {
			  		  FurnitureattributeData[] dataMixColour2 = FurnitureattributeData.selectAttributevalue(this, strMixAttributeId2);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strMixAttributeId2, dataMixColour2[0].name, "", "","20","N");
					valueatt = valueatt + " Puerta2: "+dataMixColour2[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","20","N");
		  }
		  if (!"".equals(strMixAttributeId3)) {
					FurnitureattributeData[] dataMixColour3 = FurnitureattributeData.selectAttributevalue(this, strMixAttributeId3);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strMixAttributeId3, dataMixColour3[0].name, "", "","30","N");
										valueatt = valueatt + " Puerta3: "+dataMixColour3[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","30","N");
		  }
		  if (!"".equals(strMixAttributeId4)) {
					  FurnitureattributeData[] dataMixColour4 = FurnitureattributeData.selectAttributevalue(this, strMixAttributeId4);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strMixAttributeId4, dataMixColour4[0].name, "", "","40","N");
										valueatt = valueatt + " Puerta4: "+dataMixColour4[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","40","N");
		  }
		  if (!"".equals(strMixAttributeId5)) {
					  FurnitureattributeData[] dataMixColour5 = FurnitureattributeData.selectAttributevalue(this, strMixAttributeId5);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strMixAttributeId5, dataMixColour5[0].name, "", "","50","N");
					valueatt = valueatt + " Puerta5: "+dataMixColour5[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","50","N");
		  }
		  if (!"".equals(strMixAttributeId6)) {
					  FurnitureattributeData[] dataMixColour6 = FurnitureattributeData.selectAttributevalue(this, strMixAttributeId6);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strMixAttributeId6, dataMixColour6[0].name, "", "","60","N");
					valueatt = valueatt + " Puerta6: "+dataMixColour6[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","60","N");
		  }
		  if (!"".equals(strMixAttributeId7)) {
					  FurnitureattributeData[] dataMixColour7 = FurnitureattributeData.selectAttributevalue(this, strMixAttributeId7);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strMixAttributeId7, dataMixColour7[0].name, "", "","70","N");
					valueatt = valueatt + " Puerta7: "+dataMixColour7[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","70","N");
		  }
		  if (!"".equals(strMixAttributeId8)) {
					  FurnitureattributeData[] dataMixColour8 = FurnitureattributeData.selectAttributevalue(this, strMixAttributeId8);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strMixAttributeId8, dataMixColour8[0].name, "", "","80","N");
										valueatt = valueatt + " Puerta8: "+dataMixColour8[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","80","N");
		  }
		  if (!"".equals(strMixAttributeId9)) {
					  FurnitureattributeData[] dataMixColour9 = FurnitureattributeData.selectAttributevalue(this, strMixAttributeId9);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strMixAttributeId9, dataMixColour9[0].name, "", "","90","N");
										valueatt = valueatt + " Puerta9: "+dataMixColour9[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","90","N");
		  }
		  if (!"".equals(strMixAttributeId10)) {
					  FurnitureattributeData[] dataMixColour10 = FurnitureattributeData.selectAttributevalue(this, strMixAttributeId10);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strMixAttributeId10, dataMixColour10[0].name, "", "","100","N");
										valueatt = valueatt + " Puerta10: "+dataMixColour10[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","100","N");
		  }
		  if (!"".equals(strMixAttributeId11)) {
					  FurnitureattributeData[] dataMixColour11 = FurnitureattributeData.selectAttributevalue(this, strMixAttributeId11);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strMixAttributeId11, dataMixColour11[0].name, "", "","110","N");
										valueatt = valueatt + " Puerta11: "+dataMixColour11[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","110","N");
		  }
		  if (!"".equals(strMixAttributeId12)) {
					  FurnitureattributeData[] dataMixColour12 = FurnitureattributeData.selectAttributevalue(this, strMixAttributeId12);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strMixAttributeId12, dataMixColour12[0].name, "", "","120","N");
										valueatt = valueatt + " Puerta12: "+dataMixColour12[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","120","N");
		  }


	   //Insert Drawer colour 
		  if (!"".equals(strDrawerAttributeId1)) {
							  FurnitureattributeData[] dataDrawerColour1 = FurnitureattributeData.selectAttributevalue(this, strDrawerAttributeId1);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strDrawerAttributeId1, dataDrawerColour1[0].name, "", "","10","Y");
															valueatt = valueatt + " Cajon1: "+dataDrawerColour1[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","10","Y");
		  }
		  if (!"".equals(strDrawerAttributeId2)) {
					  FurnitureattributeData[] dataDrawerColour2 = FurnitureattributeData.selectAttributevalue(this, strDrawerAttributeId2);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strDrawerAttributeId2, dataDrawerColour2[0].name, "", "","20","Y");
					valueatt = valueatt + " Cajon2: "+dataDrawerColour2[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","20","Y");
		  }
		  if (!"".equals(strDrawerAttributeId3)) {
					  FurnitureattributeData[] dataDrawerColour3 = FurnitureattributeData.selectAttributevalue(this, strDrawerAttributeId3);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strDrawerAttributeId3, dataDrawerColour3[0].name, "", "","30","Y");
					valueatt = valueatt + " Cajon3: "+dataDrawerColour3[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","30","Y");
		  }
		  if (!"".equals(strDrawerAttributeId4)) {
					  FurnitureattributeData[] dataDrawerColour4 = FurnitureattributeData.selectAttributevalue(this, strDrawerAttributeId4);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strDrawerAttributeId4, dataDrawerColour4[0].name, "", "","40","Y");
					valueatt = valueatt + " Cajon4: "+dataDrawerColour4[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","40","Y");
		  }
		  if (!"".equals(strDrawerAttributeId5)) {
					  FurnitureattributeData[] dataDrawerColour5 = FurnitureattributeData.selectAttributevalue(this, strDrawerAttributeId5);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strDrawerAttributeId5, dataDrawerColour5[0].name, "", "","50","Y");
					valueatt = valueatt + " Cajon5: "+dataDrawerColour5[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","50","Y");
		  }
		  if (!"".equals(strDrawerAttributeId6)) {
					  FurnitureattributeData[] dataDrawerColour6 = FurnitureattributeData.selectAttributevalue(this, strDrawerAttributeId6);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strDrawerAttributeId6, dataDrawerColour6[0].name, "", "","60","Y");
					valueatt = valueatt + " Cajon6: "+dataDrawerColour6[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","60","Y");
		  }
		  if (!"".equals(strDrawerAttributeId7)) {
					  FurnitureattributeData[] dataDrawerColour7 = FurnitureattributeData.selectAttributevalue(this, strDrawerAttributeId7);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strDrawerAttributeId7, dataDrawerColour7[0].name, "", "","70","Y");
					valueatt = valueatt + " Cajon7: "+dataDrawerColour7[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","70","Y");
		  }
		  if (!"".equals(strDrawerAttributeId8)) {
					  FurnitureattributeData[] dataDrawerColour8 = FurnitureattributeData.selectAttributevalue(this, strDrawerAttributeId8);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strDrawerAttributeId8, dataDrawerColour8[0].name, "", "","80","Y");
					valueatt = valueatt + " Cajon8: "+dataDrawerColour8[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","80","Y");
		  }
		  if (!"".equals(strDrawerAttributeId9)) {
					  FurnitureattributeData[] dataDrawerColour9 = FurnitureattributeData.selectAttributevalue(this, strDrawerAttributeId9);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strDrawerAttributeId9, dataDrawerColour9[0].name, "", "","90","Y");
					valueatt = valueatt + " Cajon9: "+dataDrawerColour9[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","90","Y");
		  }
		  if (!"".equals(strDrawerAttributeId10)) {
					  FurnitureattributeData[] dataDrawerColour10 = FurnitureattributeData.selectAttributevalue(this, strDrawerAttributeId10);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strDrawerAttributeId10, dataDrawerColour10[0].name, "", "","100","Y");
					valueatt = valueatt + " Cajon10: "+dataDrawerColour10[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","100","Y");
		  }
		  if (!"".equals(strDrawerAttributeId11)) {
							  FurnitureattributeData[] dataDrawerColour11 = FurnitureattributeData.selectAttributevalue(this, strDrawerAttributeId11);
							  strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strDrawerAttributeId11, dataDrawerColour11[0].name, "", "","110","Y");
					valueatt = valueatt + " Cajon11: "+dataDrawerColour11[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","110","Y");
		  }
		  if (!"".equals(strDrawerAttributeId12)) {
					  FurnitureattributeData[] dataDrawerColour12 = FurnitureattributeData.selectAttributevalue(this, strDrawerAttributeId12);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strDrawerAttributeId12, dataDrawerColour12[0].name, "", "","120","Y");
					valueatt = valueatt + " Cajon12: "+dataDrawerColour12[0].name + ";";
		  } else {
		  			strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strMixAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
					"", "", "", "","120","Y");
		  }

      /*if (strMixAttributeId.startsWith("(")) strMixAttributeId = strMixAttributeId.substring(1, strMixAttributeId.length() - 1);
      if (!strMixAttributeId.equals("")) {
			strMixAttributeId = Replace.replace(strMixAttributeId, "'", "");
			StringTokenizer st = new StringTokenizer(strMixAttributeId, ",", false);
			int i = 1;
			// Three options: 
			// 1) The quantity <> 0 and the attributevalue+attribute exists - update quantity
			// 2) The quantity = 0 or empty and the attributevalue+attribute exists - delete
			// 3) The quantity <> 0 and the attributevalue+attribute does not exist - insert
			//
			// Simplest: delete all the lines related to this instance and belongs to mix attributes and insert them again.
			//
			
			int deleteLines = FurnitureattributeData.deleteLines(this, strSetInstance);
			log4j.debug("Furniture attribute selector - lines deleted: " + deleteLines);
			//FurnitureattributeData[] dataAttributeMix = FurnitureattributeData.selectAttributeMix(this, strSetInstance);
			int deleteHeader = FurnitureattributeData.delete(this, strSetInstance);
			log4j.debug("Furniture attribute selector - header deleted: " + deleteHeader);
			strmAttributeinstanceId = SequenceIdData.getUUID();
			while (st.hasMoreTokens()) {
				String strmAttributevalueId = st.nextToken().trim();
				 if (!"".equals(strmAttributevalueId)) { 
					log4j.debug("Furniture attribute selector - attribute value id: " + strmAttributevalueId);
					dataValue = FurnitureattributeData.selectAttributevalue(this, strmAttributevalueId);
					//log4j.debug("Furniture attribute selector - attribute value: " + dataValue[0].name);
					//strmAttributeinstanceId = SequenceIdData.getUUID();
					String quantity = "1";
					log4j.debug("Furniture attribute selector - quantity: " + quantity);

					if (i==1) FurnitureattributeData.insert(this, strmAttributeinstanceId, strSetInstance.equals("") ? mAttributesetInstanceId : strSetInstance, dataValue[0].mAttributeId, vars.getClient(), vars.getOrg(), vars.getUser(), strmAttributevalueId, dataValue[0].name, "", "");
	  
					if (!"".equals(quantity) && !"0".equals(quantity)) {
					   log4j.debug("Furniture attribute selector - insert attribute - length: "+dataValue.length);
					   String pecmAttributeInstanceId = SequenceIdData.getUUID();
					   FurnitureattributeData.insertAttributeinstLine(this, pecmAttributeInstanceId, strmAttributeinstanceId, dataValue[0].mAttributeId, vars.getClient(), vars.getOrg(), vars.getUser(), strmAttributevalueId, dataValue[0].name, "", quantity);
					}
				}
				i++;
			}
      }*/

      // Insert g handle
		String strHandleAttMain = FurnitureattributeData.selectHandleAttMain(this);
		  if (!"".equals(strHandleId1)) {
			  		  FurnitureattributeData[] dataHandle1 = FurnitureattributeData.selectAttributevalue(this, strHandleId1);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strHandleAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strHandleColourId1, dataHandle1[0].name, strHandleId1, strHandleQuantityId1,"10","N");
						valueatt = valueatt + strHandleQuantityId1 + " tiradores "+dataHandle1[0].name + ";";

		  } else {
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strHandleAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strHandleColourId1, "", "", strHandleQuantityId1,"10","N");
		  }
		  if (!"".equals(strHandleId2)) {
					  FurnitureattributeData[] dataHandle2 = FurnitureattributeData.selectAttributevalue(this, strHandleId2);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strHandleAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strHandleColourId2, dataHandle2[0].name, strHandleId2, strHandleQuantityId2,"20","N");
											valueatt = valueatt + strHandleQuantityId2 + " tiradores "+dataHandle2[0].name + ";";
		  } else {
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strHandleAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strHandleColourId2, "", "", strHandleQuantityId2,"20","N");
		  }
		  if (!"".equals(strHandleId3)) {
					  FurnitureattributeData[] dataHandle3 = FurnitureattributeData.selectAttributevalue(this, strHandleId3);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strHandleAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strHandleColourId3, dataHandle3[0].name, strHandleId3, strHandleQuantityId3,"30","N");
											valueatt = valueatt + strHandleQuantityId3 + " tiradores "+dataHandle3[0].name + ";";
		  } else {
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strHandleAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strHandleColourId3, "", "", strHandleQuantityId3,"30","N");
		  }
		  if (!"".equals(strHandleId4)) {
					  FurnitureattributeData[] dataHandle4 = FurnitureattributeData.selectAttributevalue(this, strHandleId4);
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strHandleAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strHandleColourId4, dataHandle4[0].name, strHandleId4, strHandleQuantityId4,"40","N");
											valueatt = valueatt + strHandleQuantityId4 + " tiradores "+dataHandle4[0].name + ";";
		  } else {
					strmAttributeinstanceId = SequenceIdData.getUUID();
					FurnitureattributeData.insertAttributeinstLine(this, strmAttributeinstanceId, mAttributesetInstanceId, strHandleAttMain, vars.getClient(), vars.getOrg(), vars.getUser(), 
						strHandleColourId4, "", "", strHandleQuantityId4,"40","N");
		  }

FurnitureattributeData.updateHeader(this, valueatt, mAttributesetInstanceId);
      // Handle -> Attribute -> Attributevalue
      // Identifier = pechandleid + attributevalue
     /* String identifier = vars.getStringParameter("inppecHandleId", "");
      //if (identifier.startsWith("(")) identifier = identifier.substring(1, identifier.length() - 1);
      if (!"".equals(identifier)) {
			String strpecHandleId = identifier.substring(0, 31);
			String strmAttributevalueId = identifier.substring(32, 63);
			dataValue = FurnitureattributeData.selectAttributevalue(this, strmAttributevalueId);
			log4j.debug("Furniture attribute selector - handle value: " + dataValue[0].name);
			//FurnitureattributeData[] dataAttributeHandle = FurnitureattributeData.selectAttributeHandle(this, strInstance);
			if ("".equals(strSetInstance)) {
			  // Insert handle
				  strmAttributeinstanceId = SequenceIdData.getUUID();
				  FurnitureattributeData.insert(this, strmAttributeinstanceId, mAttributesetInstanceId, dataValue[0].mAttributeId, vars.getClient(), vars.getOrg(), vars.getUser(), strmAttributevalueId, dataValue[0].name, strpecHandleId, "1");
			} else {
				  // Update handle
				  if (!"".equals(strmAttributevalueId)) {
					FurnitureattributeData[] dataAttributeHandle = FurnitureattributeData.selectAttributeHandle(this, strSetInstance);
					FurnitureattributeData.update(this, vars.getUser(), dataAttributeHandle[0].mAttributevalueId, dataValue[0].name, strSetInstance,  dataAttributeHandle[0].mAttributeId);
				  }
			}
		}*/

      }

      //OBError myMessage = attSetValue.setAttributeInstance(this, vars, strAttributeSet,
        //  strInstance, strWindowId, strIsSOTrx, strProduct, attValues);
//      vars.setSessionValue("Furnitureattribute.instance", attSetValue.getAttSetInstanceId());
//      vars.setSessionValue("Furnitureattribute.instance", attributesetinstance.equals("") ? (strSetInstance.equals("") ? mAttributesetInstanceId : strSetInstance) : attributesetinstance);
      vars.setSessionValue("Furnitureattribute.instance", mAttributesetInstanceId);
      vars.setSessionValue("Furnitureattribute.attribute", strAttributeSet);
      vars.setSessionValue("Furnitureattribute.close", "Y");
//      vars.setMessage(strTabId, myMessage);
      // vars.setSessionValue("Furnitureattribute.message", strMessage);
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=DISPLAY");
    } else
      pageErrorPopUp(response);
  }

  private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strInstance,
      String strAttributeSet, String strProductInstance, String strWindowId, String strTabId,
      String strLocator, String strIsSOTrx, String strProduct, String strKey, String strType) throws IOException, ServletException {



	String discard[] = { "selEliminarSofa" };



    if (log4j.isDebugEnabled())
      log4j.debug("Output: Frame 1 of the attributes seeker");

		if (strType.equals("") && strInstance.equals("")) discard[0] = "selEliminarSofa";
		if (!strType.equals("") && strInstance.equals(""))
		{
			if (strType.equals("armario")) discard[0] = "selEliminarSofa";
			else discard[0] = "selEliminarArmarios";
		}
		FurnitureattributeData[] dataHeaderAtt = FurnitureattributeData.selectHeaderAtt(this, strInstance);
		if (!"".equals(strInstance)) {
				if (strType.equals(""))
				{
					if (dataHeaderAtt[0].type.equals("armario")) discard[0] = "selEliminarSofa";
					else discard[0] = "selEliminarArmarios";
				} else {
					if (strType.equals("armario")) discard[0] = "selEliminarSofa";
					else discard[0] = "selEliminarArmarios";
				}
		}

XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/furniture/info/Furnitureattribute", discard).createXmlDocument();

      xmlDocument.setParameter("css", vars.getTheme());
    {
      OBError myMessage = vars.getMessage("Furnitureattribute");
      vars.removeMessage("Furnitureattribute");
      if (myMessage != null) {
        xmlDocument.setParameter("messageType", myMessage.getType());
        xmlDocument.setParameter("messageTitle", myMessage.getTitle());
        xmlDocument.setParameter("messageMessage", myMessage.getMessage());
      }
    }
    String message = "";
    if (vars.getSessionValue("Furnitureattribute.close").equals("Y"))
      message = "printMessage('')";
    xmlDocument.setParameter("body", message);




		if (strType.equals("") && strInstance.equals("")) {
			xmlDocument.setParameter("armario","armario");
			xmlDocument.setParameter("sofa", "armario");
		}
		if (!strType.equals("") && strInstance.equals("")) {
			xmlDocument.setParameter("armario",strType);
			xmlDocument.setParameter("sofa", strType);
		}
		if (!"".equals(strInstance)) {
				if (strType.equals(""))
				{
						xmlDocument.setParameter("armario", dataHeaderAtt[0].type);
						xmlDocument.setParameter("sofa", dataHeaderAtt[0].type);
				} else {
						xmlDocument.setParameter("armario", strType);
						xmlDocument.setParameter("sofa", strType);
				}
		}

    xmlDocument.setParameter("calendar", vars.getLanguage().substring(0, 2));
    xmlDocument.setParameter("directory", "var baseDirectory = \"" + strReplaceWith + "/\";\n");
    xmlDocument.setParameter("language", "defaultLang=\"" + vars.getLanguage() + "\";");
    xmlDocument.setParameter("theme", vars.getTheme());
    xmlDocument.setParameter("attribute", strAttributeSet);
    xmlDocument.setParameter("windowId", strWindowId);
    xmlDocument.setParameter("tabId", strTabId);
    xmlDocument.setParameter("locatorId", strLocator);



    /*
     * String message = vars.getSessionValue("Furnitureattribute.message");
     * vars.removeSessionValue("Furnitureattribute.message"); if (!message.equals("")) { if
     * (!message.equals("OK")) message = "alert('" + message + "');"; else message =
     * "printMessage('');"; } xmlDocument.setParameter("body", message);
     */
   
    if (strInstance.equals("")
        && FurnitureattributeData.isInstanceAttribute(this, strAttributeSet).equals("0"))
      strInstance = strProductInstance;

    xmlDocument.setParameter("instance", strInstance);
    xmlDocument.setParameter("product", strProduct);
    //FurnitureattributeData[] dataOrderline = null; 
    if (!"".equals(strInstance)) {

      xmlDocument.setParameter("alldoors", dataHeaderAtt[0].emPecAllDoors);
      xmlDocument.setParameter("platdoors", dataHeaderAtt[0].emPecDoorsPlatfones);
      xmlDocument.setParameter("izdadchadoors", dataHeaderAtt[0].emPecDoorsLeftright);
      xmlDocument.setParameter("updowndoors", dataHeaderAtt[0].emPecDoorsUpdown);
      xmlDocument.setParameter("alldrawers", dataHeaderAtt[0].emPecAllDrawers);
      xmlDocument.setParameter("platdrawers", dataHeaderAtt[0].emPecDrawersPlatfones);
      xmlDocument.setParameter("izdadchadrawers", dataHeaderAtt[0].emPecDrawersLeftright);
      xmlDocument.setParameter("updowndrawers", dataHeaderAtt[0].emPecDrawersUpdown);
	  xmlDocument.setParameter("attprice", dataHeaderAtt[0].emPecAttprice);

	  if (!dataHeaderAtt[0].type.equals("A"))
	  {

		 FurnitureattributeData[] dataSofaAtt = FurnitureattributeData.selectSofaAtt(this, strInstance);
        for (int i=0; i<dataSofaAtt.length; i++) {
          xmlDocument.setParameter("sofa"+(new Integer(i+1)).toString(), dataSofaAtt[i].mAttributevalueId);
        }
	  }


      //dataOrderline = FurnitureattributeData.selectOrderline(this, strKey);
      //if (dataOrderline!=null || dataOrderline.length>0) {
        log4j.debug("Furniture attribute - select attribute base - instance: "+strInstance);
        FurnitureattributeData[] dataAttributeBase = FurnitureattributeData.selectAttributeBase(this, strInstance);
		log4j.debug("Furniture attribute - select attribute base - instance - setParameter base - length: "+dataAttributeBase.length);
		if (dataAttributeBase!=null && dataAttributeBase.length>0) xmlDocument.setParameter("colourBase", dataAttributeBase[0].mAttributevalueId);

		FurnitureattributeData[] dataAttributeMetal = FurnitureattributeData.selectAttributeMetal(this, strInstance);
		log4j.debug("Furniture attribute - select attribute metal - instance - setParameter base - length: "+dataAttributeMetal.length);
		if (dataAttributeMetal!=null && dataAttributeMetal.length>0) {
			log4j.debug("Furniture attribute - select attribute metal - instance - setParameter metal - length: "+dataAttributeMetal[0].mAttributevalueId);
			xmlDocument.setParameter("colourMetal", dataAttributeMetal[0].mAttributevalueId);
		}

        log4j.debug("Furniture attribute - select attribute handle - instance: "+strInstance);
        FurnitureattributeData[] dataAttributeHandle = FurnitureattributeData.selectAttributeHandle(this, strInstance);
		log4j.debug("Furniture attribute - select attribute base - instance - setParameter handle - length: "+dataAttributeHandle.length);
	if (dataAttributeHandle!=null && dataAttributeHandle.length>0) { 
		xmlDocument.setParameter("handle1", dataAttributeHandle[0].emPecTiradorId);
		xmlDocument.setParameter("quantityhandle1", dataAttributeHandle[0].emPecQuantity);
		xmlDocument.setParameter("colourHandle1", dataAttributeHandle[0].mAttributevalueId); }
	if (dataAttributeHandle!=null && dataAttributeHandle.length>1) { 
		xmlDocument.setParameter("handle2", dataAttributeHandle[1].emPecTiradorId);
		xmlDocument.setParameter("quantityhandle2", dataAttributeHandle[1].emPecQuantity);
		xmlDocument.setParameter("colourHandle2", dataAttributeHandle[1].mAttributevalueId); }	
	if (dataAttributeHandle!=null && dataAttributeHandle.length>2) { 
		xmlDocument.setParameter("handle3", dataAttributeHandle[2].emPecTiradorId);
		xmlDocument.setParameter("quantityhandle3", dataAttributeHandle[2].emPecQuantity);
		xmlDocument.setParameter("colourHandle3", dataAttributeHandle[2].mAttributevalueId); }	
	if (dataAttributeHandle!=null && dataAttributeHandle.length>3) { 
		xmlDocument.setParameter("handle4", dataAttributeHandle[3].emPecTiradorId);
		xmlDocument.setParameter("quantityhandle4", dataAttributeHandle[3].emPecQuantity);
		xmlDocument.setParameter("colourHandle4", dataAttributeHandle[3].mAttributevalueId); }

        FurnitureattributeData[] dataAttributeMix = FurnitureattributeData.selectAttributeMixDrawer(this, strInstance,"N");
        log4j.debug("Furniture attribute - select attribute base - instance - setParameter mix - length: "+dataAttributeMix.length);
        for (int i=0; i<dataAttributeMix.length; i++) {
          xmlDocument.setParameter("colourMix"+(new Integer(i+1)).toString(), dataAttributeMix[i].mAttributevalueId);
        }

        FurnitureattributeData[] dataAttributeDrawer = FurnitureattributeData.selectAttributeMixDrawer(this, strInstance,"Y");
        log4j.debug("Furniture attribute - select attribute base - instance - setParameter mix - length: "+dataAttributeMix.length);
        for (int i=0; i<dataAttributeDrawer.length; i++) {
          xmlDocument.setParameter("colourDrawer"+(new Integer(i+1)).toString(), dataAttributeDrawer[i].mAttributevalueId);
        }
		    

        xmlDocument.setParameter("mAttributesetinstanceId", strInstance);
      //}
    } else {
		if ("".equals(strType)) {
			 xmlDocument.setParameter("armario", "armario");
			 xmlDocument.setParameter("sofa", "armario");
		} else {
			 xmlDocument.setParameter("armario", strType);
			 xmlDocument.setParameter("sofa", strType);
		}
	}

    log4j.debug("Furniture attribute - before print combos");
    String strmProductCategoryId = FurnitureattributeData.selectProductCategory(this, strProduct); 
    
    FurnitureattributeData[] dataColour = FurnitureattributeData.selectColour(this, strmProductCategoryId, "Y");

    //FurnitureattributeData[] dataAttributeBase = FurnitureattributeData.selectAttributeBase(this, dataOrderline==null ? "" : dataOrderline[0].mAttributesetinstanceId);
    log4j.debug("Furniture attribute - colour base");
    //xmlDocument.setParameter("colourBase", dataAttributeBase==null ? "" : dataAttributeBase[0].mAttributevalueId);
    xmlDocument.setData("reportColour", "liststructure", dataColour);
	
	xmlDocument.setData("reportArmazon", "liststructure", dataColour);
	xmlDocument.setData("reportAsientos", "liststructure", dataColour);
	xmlDocument.setData("reportRespaldos", "liststructure", dataColour);
	xmlDocument.setData("reportApoyaBrazos", "liststructure", dataColour);
	xmlDocument.setData("reportPuffs", "liststructure", dataColour);
	xmlDocument.setData("reportCojines", "liststructure", dataColour);
    
    log4j.debug("Furniture attribute - after colour base");

    FurnitureattributeData[] dataHandle = FurnitureattributeData.selectHandle(this, strmProductCategoryId, "Y");

    //FurnitureattributeData[] dataAttributeHandle = FurnitureattributeData.selectAttributeHandle(this, dataOrderline==null ? "" : dataOrderline[0].mAttributesetinstanceId);
    log4j.debug("Furniture attribute - handle");
    //xmlDocument.setParameter("handle", dataAttributeHandle == null ? "" : dataAttributeHandle[0].mAttributevalueId);

    FurnitureattributeData[] dataColourMix = FurnitureattributeData.selectColourMix(this, strmProductCategoryId, "Y");

    //FurnitureattributeData[] dataAttributeMix = FurnitureattributeData.selectAttributeMix(this, dataOrderline==null ? "" : dataOrderline[0].mAttributesetinstanceId);

    log4j.debug("Furniture attribute - for print mix colours");
    /*for (int i=0; i<dataAttributeMix.length; i++) {
      xmlDocument.setParameter("colourMix"+dataAttributeMix == null ? "" : (new Integer(i+1)).toString(), dataAttributeMix[0].mAttributevalueId);
      xmlDocument.setParameter("quantity"+dataAttributeMix == null ? "" : (new Integer(i+1)).toString(), dataAttributeMix[0].quantity);
    }*/





    xmlDocument.setData("reportColourMix1", "liststructure", dataColourMix);
    xmlDocument.setData("reportColourMix2", "liststructure", dataColourMix);
    xmlDocument.setData("reportColourMix3", "liststructure", dataColourMix);
    xmlDocument.setData("reportColourMix4", "liststructure", dataColourMix);
    xmlDocument.setData("reportColourMix5", "liststructure", dataColourMix);
    xmlDocument.setData("reportColourMix6", "liststructure", dataColourMix);
    xmlDocument.setData("reportColourMix7", "liststructure", dataColourMix);
	xmlDocument.setData("reportColourMix8", "liststructure", dataColourMix);
	xmlDocument.setData("reportColourMix9", "liststructure", dataColourMix);
	xmlDocument.setData("reportColourMix10", "liststructure", dataColourMix);
	xmlDocument.setData("reportColourMix11", "liststructure", dataColourMix);
	xmlDocument.setData("reportColourMix12", "liststructure", dataColourMix);


	xmlDocument.setData("reportColourDrawer1", "liststructure", dataColourMix);
    xmlDocument.setData("reportColourDrawer2", "liststructure", dataColourMix);
    xmlDocument.setData("reportColourDrawer3", "liststructure", dataColourMix);
    xmlDocument.setData("reportColourDrawer4", "liststructure", dataColourMix);
    xmlDocument.setData("reportColourDrawer5", "liststructure", dataColourMix);
    xmlDocument.setData("reportColourDrawer6", "liststructure", dataColourMix);
    xmlDocument.setData("reportColourDrawer7", "liststructure", dataColourMix);
	xmlDocument.setData("reportColourDrawer8", "liststructure", dataColourMix);
	xmlDocument.setData("reportColourDrawer9", "liststructure", dataColourMix);
	xmlDocument.setData("reportColourDrawer10", "liststructure", dataColourMix);
	xmlDocument.setData("reportColourDrawer11", "liststructure", dataColourMix);
	xmlDocument.setData("reportColourDrawer12", "liststructure", dataColourMix);

    xmlDocument.setData("reportHandle1", "liststructure", dataHandle);
    xmlDocument.setData("reportHandle2", "liststructure", dataHandle);
	xmlDocument.setData("reportHandle3", "liststructure", dataHandle);
	xmlDocument.setData("reportHandle4", "liststructure", dataHandle);

	xmlDocument.setData("reportColourHandle1", "liststructure", dataColourMix);
	xmlDocument.setData("reportColourHandle2", "liststructure", dataColourMix);
	xmlDocument.setData("reportColourHandle3", "liststructure", dataColourMix);
	xmlDocument.setData("reportColourHandle4", "liststructure", dataColourMix);
    log4j.debug("Furniture attribute - set parameter");

    FurnitureattributeData[] dataColourMetal = FurnitureattributeData.selectColourMetal(this, strmProductCategoryId, "Y");

    xmlDocument.setData("reportMetal", "liststructure", dataColourMetal);
    //xmlDocument.setParameter("mAttributesetinstanceId", dataOrderline==null ? "" : dataOrderline[0].mAttributesetinstanceId);
    
    /*String strName = Utility.messageBD(this, "Description", vars.getLanguage());
    xmlDocument.setParameter("nameDescription", strName.equals("") ? "Description" : strName);
    xmlDocument.setParameter("description", FurnitureattributeData.selectDescription(this,
        (strInstance.equals("") ? strProductInstance : strInstance)));*/
    FurnitureattributeData[] data = FurnitureattributeData.select(this, strAttributeSet);
    xmlDocument.setParameter("data",generateHtml(vars, data, FurnitureattributeData.selectInstance(this,(strInstance.equals("") ? strProductInstance : strInstance)), strInstance, strIsSOTrx,strWindowId));
    xmlDocument.setParameter("script", generateScript(vars, data));
    response.setContentType("text/html; charset=UTF-8");
    PrintWriter out = response.getWriter();
    out.println(xmlDocument.print());
    out.close();
  }

  private String instanceValue(FurnitureattributeData[] instanceData, String strAttributeId,
      boolean isList) {
    if (instanceData == null || instanceData.length == 0)
      return "";
    for (int i = 0; i < instanceData.length; i++) {
      if (instanceData[i].mAttributeId.equals(strAttributeId)) {
        if (isList)
          return instanceData[i].mAttributevalueId;
        else
          return instanceData[i].value;
      }
    }
    return "";
  }

  private String attributesetinstanceCheck(VariablesSecureApp vars, String baseattribute, String metalattribute, String mixattribute, String handleattribute)
      throws IOException, ServletException {
      
      // Execute a sql with the base attribute and the metal attribute to obtain the attribute set instance

      log4j.debug("Furniture attribute - attribute set instance check if already exists - base attribute: "+baseattribute);
      log4j.debug("Furniture attribute - attribute set instance check if already exists - metal attribute: "+metalattribute);
      log4j.debug("Furniture attribute - attribute set instance check if already exists - mix attribute: "+mixattribute);
      log4j.debug("Furniture attribute - attribute set instance check if already exists - handle attribute: "+handleattribute);
      String baseandmetal = "";
      if (!"".equals(baseattribute)) {
        baseandmetal = baseandmetal + "('" + baseattribute + "'";
      }
      if (!"".equals(metalattribute)) {
        if ("".equals(baseandmetal)) baseandmetal = baseandmetal + "(";
	else baseandmetal = baseandmetal + ",";
	baseandmetal = baseandmetal + "'" + metalattribute + "'";
      }
      if (!"".equals(baseandmetal)) baseandmetal += ")";

      String attributeinstanceid = "";
      log4j.debug("Furniture attribute - attribute set instance check if already exists - base and metal combined: "+baseandmetal);
      if (!"".equals(baseandmetal)) attributeinstanceid = FurnitureattributeData.selectBaseandMetal(this, baseandmetal);

      log4j.debug("Furniture attribute - attribute set instance check if already exists - attribute instance after checks base and metal: "+attributeinstanceid);
      
      if (!"".equals(attributeinstanceid)) {
        // If the attribute set instance match in the first parameters (base and metal), check if mix matches
	// Two checks: 
	// 1) Check if all the mixes selected + quantity matches
	// 2) Check if there is no other mix parameter in this attribute set instance
        if (mixattribute.startsWith("(")) mixattribute = mixattribute.substring(1, mixattribute.length() - 1);
        if (!mixattribute.equals("")) {
          mixattribute = Replace.replace(mixattribute, "'", "");
	  StringTokenizer st = new StringTokenizer(mixattribute, ",", false);
	  String accumulatedAttributevalue = "";
	  int i=1;
	  while (st.hasMoreTokens()) {
	    String strmAttributevalueId = st.nextToken().trim();
            log4j.debug("Furniture attribute - attribute set instance check if already exists - mix attribute: "+strmAttributevalueId);
            String quantity = "1";
	    log4j.debug("Furniture attribute - attribute set instance check if already exists - quantity: "+quantity);
	    // check if the attribue value + quantity + attribute set instance matches
	    String count = FurnitureattributeData.selectCheckMix(this, strmAttributevalueId, quantity, attributeinstanceid);
	    log4j.debug("Furniture attribute - attribute set instance check if already exists - count: "+count);
	    if (!"".equals(strmAttributevalueId) && strmAttributevalueId != null) {
	      if ("0".equals(count)) return "";
              if (!"".equals(accumulatedAttributevalue)) accumulatedAttributevalue += ",";
	      accumulatedAttributevalue = accumulatedAttributevalue + "'" + strmAttributevalueId + "'";
	      log4j.debug("Furniture attribute - attribute set instance check if already exists - accumulated attribute: "+accumulatedAttributevalue);
	    }
	    i++;
	  }
	  // Once that all the mix attributes are in the attribute set instance, check if there are other mixed attributes. If yes, this instance does not match
	  if (!"".equals(accumulatedAttributevalue)) accumulatedAttributevalue = "(" + accumulatedAttributevalue + ")";
	  String countmore = FurnitureattributeData.selectCheckMixMore(this, accumulatedAttributevalue, attributeinstanceid);
	  log4j.debug("Furniture attribute - attribute set instance check if already exists - count more: "+countmore);
	  if (!"0".equals(countmore)) return "";
        }
      }

      return attributeinstanceid;

  }

  private String generateScript(VariablesSecureApp vars, FurnitureattributeData[] fields)
      throws IOException, ServletException {
    if (fields == null || fields.length == 0)
      return "";
    StringBuffer strHtml = new StringBuffer();
    strHtml.append("function onloadFunctions() {\n");
    strHtml.append("  return true;\n");
    strHtml.append("}\n");
    return strHtml.toString();
  }

  private String generateHtml(VariablesSecureApp vars, FurnitureattributeData[] fields,
      FurnitureattributeData[] instanceData, String strAttributeInstance, String strIsSOTrx,
      String strWindowId) throws IOException, ServletException {
    if (fields == null || fields.length == 0)
      return "";
    StringBuffer strHtml = new StringBuffer();
    if (!fields[0].elementname.equals("")) {
      for (int i = 0; i < fields.length; i++) {
        strHtml.append("<tr><td class=\"TitleCell\"><span class=\"LabelText\">");
        // String strName = Utility.messageBD(this,
        // fields[i].elementname, vars.getLanguage());
        // strHtml.append(strName.equals("")?fields[i].elementname:strName);
        strHtml.append(fields[i].elementname);
        strHtml.append("</span></td>\n");
        strHtml.append("<td class=\"LabelText\">");
        String strValue = instanceValue(instanceData, fields[i].mAttributeId,
            fields[i].islist.equals("Y"));
        if (fields[i].islist.equals("Y")) {
          strHtml.append("<select ");
          strHtml.append("name=\"inp" + replace(fields[i].elementname) + "\" ");
          strHtml.append("class=\"Combo");
          if (fields[i].ismandatory.equals("Y"))
            strHtml.append("Key");
          strHtml.append(" Combo_OneCell_width\" ");
          strHtml.append(" id=\"").append(replace(fields[i].elementname)).append("\">");
          FurnitureattributeData[] data = FurnitureattributeData.selectList(this,
              fields[i].mAttributeId);
          if (!fields[i].ismandatory.equals("Y"))
            strHtml.append("<option value=\"\"></option>\n");
          for (int j = 0; j < data.length; j++) {
            strHtml.append("<option value=\"");
            strHtml.append(data[j].value);
            strHtml.append("\" ");
            if (data[j].value.equalsIgnoreCase(strValue))
              strHtml.append("selected");
            strHtml.append(">");
            strHtml.append(data[j].name);
            strHtml.append("</option>\n");
          }
          strHtml.append("</select>");
        } else {
          strHtml.append("<textarea ");
          strHtml.append("name=\"inp" + replace(fields[i].elementname) + "\" ");
          strHtml
              .append("class=\"dojoValidateValid TextArea_OneCell_width TextArea_OneCell_height");
          if (fields[i].ismandatory.equals("Y"))
            strHtml.append(" required");
          strHtml.append("\"");
          strHtml.append(">");
          strHtml.append(strValue);
          strHtml.append("</textarea>");
        }
        strHtml.append("</td><td></td><td></td></tr>\n");
      }
    }
    if (fields[0].islot.equals("Y")) {
      strHtml.append("<tr><td class=\"TitleCell\"><span class=\"LabelText\">");
      String strName = Utility.messageBD(this, "Lot", vars.getLanguage());
      strHtml.append(strName.equals("") ? "Lot" : strName);
      strHtml.append("</span></td>\n");
      strHtml.append("<td ");
      strHtml.append("class=\"TextBox_ContentCell\"><input type=\"text\" ");
      strHtml.append("name=\"inplot\" ");
      strHtml.append("maxlength=\"20\" ");
      strHtml.append("class=\"dojoValidateValid TextBox_OneCell_width");
      // strHtml.append("onkeydown=\"autoCompleteNumber(this, true, true, event);return true;\" ");
      if (!fields[0].mLotctlId.equals("") && (strIsSOTrx.equals("N") || strWindowId.equals("191"))) {
        strHtml.append(" readonly\" readonly=true ");
      } else {
        strHtml.append("\" ");
      }
      if (strAttributeInstance.equals("") && (strIsSOTrx.equals("N") || strWindowId.equals("191")))
        strHtml.append("value=\""
            + FurnitureattributeData.selectNextLot(this, fields[0].mLotctlId) + "\" ");
      else
        strHtml.append("value=\""
            + ((instanceData != null && instanceData.length > 0) ? instanceData[0].lot : "")
            + "\" ");
      strHtml.append("></td><td></td><td></td></tr>\n");
    }
    if (fields[0].isserno.equals("Y")) {
      strHtml.append("<tr><td class=\"TitleCell\"><span class=\"LabelText\">");
      String strName = Utility.messageBD(this, "SerNo", vars.getLanguage());
      strHtml.append(strName.equals("") ? "SerNo" : strName);
      strHtml.append("</span></td>\n");
      strHtml.append("<td class=\"TextBox_ContentCell\"><input type=\"text\" ");
      strHtml.append("name=\"inpserno\" ");
      strHtml.append("maxlength=\"20\" ");
      strHtml.append("class=\"dojoValidateValid TextBox_OneCell_width");
      // strHtml.append("onkeydown=\"autoCompleteNumber(this, true, true, event);return true;\" ");
      if (!fields[0].mSernoctlId.equals("")
          && (strIsSOTrx.equals("N") || strWindowId.equals("191"))) {
        strHtml.append(" readonly\" readonly=true ");
      } else {
        strHtml.append("\" ");
      }
      if (strAttributeInstance.equals("") && (strIsSOTrx.equals("N") || strWindowId.equals("191")))
        strHtml.append("value=\""
            + FurnitureattributeData.selectNextSerNo(this, fields[0].mSernoctlId) + "\" ");
      else
        strHtml.append("value=\""
            + ((instanceData != null && instanceData.length > 0) ? instanceData[0].serno : "")
            + "\" ");
      strHtml.append("></td><td></td><td></td></tr>\n");
    }
    if (fields[0].isguaranteedate.equals("Y")) {
      if (log4j.isDebugEnabled())
        log4j.debug("GuaranteeDate:"
            + ((instanceData != null && instanceData.length > 0) ? instanceData[0].guaranteedate
                : ""));
      String strGuaranteeDate = null;

      if (strAttributeInstance.equals("") && (strIsSOTrx.equals("N") || strWindowId.equals("191")))
        strGuaranteeDate = DateTimeData.nDaysAfter(this, DateTimeData.today(this),
            fields[0].guaranteedays);
      else
        strGuaranteeDate = (instanceData != null && instanceData.length > 0) ? instanceData[0].guaranteedate
            : "";

      strHtml.append("<tr><td class=\"TitleCell\"><span class=\"LabelText\">");
      String strName = Utility.messageBD(this, "GuaranteeDate", vars.getLanguage());
      strHtml.append(strName.equals("") ? "GuaranteeDate" : strName);
      strHtml.append("</span></td>\n");
      strHtml.append("<td class=\"TextBox_btn_ContentCell\">");
      strHtml
          .append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" summary=\"\" style=\"padding-top: 0px;\">");
      strHtml.append("<tr>");
      strHtml.append("<td class=\"TextBox_ContentCell\">");
      strHtml
          .append("<input dojoType=\"openbravo:DateTextbox\" displayFormat=\""
              + vars.getSessionValue("#AD_SqlDateFormat")
              + "\" saveFormat=\""
              + vars.getSessionValue("#AD_SqlDateFormat")
              + "\" class=\"TextBox_btn_OneCell_width\"  type=\"text\" name=\"inpDateFrom\" id=\"paramDateFrom\" size=\"10\" maxlength=\"10\" value=\""
              + strGuaranteeDate
              + "\" onkeyup=\"autoCompleteDate(this.textbox, this.displayFormat);return true;\"></input><script>djConfig.searchIds.push(\"paramDateFrom\");</script>");
      strHtml.append("</td>");
      strHtml.append("<td class=\"FieldButton_ContentCell\">");
      strHtml.append("<a class=\"FieldButtonLink\" href=\"#\"");
      strHtml
          .append("onfocus=\"this.className='FieldButtonLink_hover'; window.status='Show calendar'; return true;\"");
      strHtml.append("onblur=\"this.className='FieldButtonLink'; window.status=''; return true;\"");
      strHtml.append("onkeypress=\"this.className='FieldButtonLink_active'; return true;\"");
      strHtml.append("onkeyup=\"this.className='FieldButtonLink_hover'; return true;\"");
      strHtml.append("onClick=\"showCalendar('frmMain.");
      strHtml.append("inpDateFrom', ");
      strHtml.append("document.frmMain.inpDateFrom.value, false);return false;\">");
      strHtml.append("<table class=\"FieldButton\"");
      strHtml.append("onmousedown=\"this.className='FieldButton_active'; return true;\"");
      strHtml.append("onmouseup=\"this.className='FieldButton'; return true;\"");
      strHtml
          .append("onmouseover=\"this.className='FieldButton_hover'; window.status='Show calendar'; return true;\"");
      strHtml
          .append("onmouseout=\"this.className='FieldButton'; window.status=''; return true;\">");
      strHtml.append("<tr>");
      strHtml.append("<td class=\"FieldButton_bg\">");
      strHtml
          .append(
              "<img alt=\"Calendar\" class=\"FieldButton_Icon FieldButton_Icon_Calendar\" title=\"Calendar\" src=\"")
          .append(strReplaceWith).append("/images/blank.gif\" border=\"0\"\"/>");
      strHtml.append("</td>");
      strHtml.append("</tr>");
      strHtml.append("</table>");
      strHtml.append("</a>");
      strHtml.append("</td>");
      strHtml.append("</tr>");
      strHtml.append("</table>");
      strHtml.append("</td><td></td><td></td>");
      strHtml.append("</tr>");
    }
    if (fields[0].islockable.equals("Y")) {
      strHtml.append("<tr><td class=\"TitleCell\"><span class=\"LabelText\">");
      String strName = Utility.messageBD(this, "IsLocked", vars.getLanguage());
      strHtml.append(strName.equals("") ? "IsLocked" : strName);
      strHtml.append("</span></td>\n");
      strHtml.append("<td class=\"Radio_Check_ContentCell\"><input type=\"checkbox\" ");
      strHtml.append("name=\"inpislocked\" ");
      strHtml.append("value=\"Y\" ");
      if (instanceData != null && instanceData.length > 0 && instanceData[0].islocked.equals("Y"))
        strHtml.append("checked ");
      strHtml.append("></td></tr>\n");
      strHtml.append("<tr><td class=\"TitleCell\"><span class=\"LabelText\">");
      strName = Utility.messageBD(this, "LockDescription", vars.getLanguage());
      strHtml.append(strName.equals("") ? "LockDescription" : strName);
      strHtml.append("</span></td>\n");
      strHtml.append("<td>");
      strHtml.append("<textarea ");
      strHtml.append("name=\"inplockDescription\" ");
      strHtml.append("class=\"dojoValidateValid TextArea_OneCell_width TextArea_OneCell_height");
      strHtml.append("\">");
      if (instanceData != null && instanceData.length > 0)
        strHtml.append(instanceData[0].lockDescription);
      strHtml.append("</textarea>");
      strHtml.append("</td><td></td><td></td></tr>\n");
    }
    return strHtml.toString();
  }

  private String replace(String strIni) {
    // delete characters: " ","&",","
    return Replace.replace(Replace.replace(Replace.replace(
        Replace.replace(Replace.replace(Replace.replace(strIni, "#", ""), " ", ""), "&", ""), ",",
        ""), "(", ""), ")", "");
  }

  public String getServletInfo() {
    return "Servlet that presents attributes seeker";
  } // end of getServletInfo() method
}
